<?php



function sendRequest($url, $param, $type="POST") {
	$ch = curl_init ();
	switch($type)
	{	
	  case "GET":
		curl_setopt($ch, CURLOPT_URL, $url.$param);
		curl_setopt($ch, CURLOPT_HTTPGET, 1);		# uses GET
		curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");	#cc added
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,30); 
		curl_setopt($ch, CURLOPT_TIMEOUT, 60); 		
		$result = curl_exec($ch);	
		break;
	  case "POST":
		curl_setopt($ch, CURLOPT_URL,$url);
		curl_setopt($ch, CURLOPT_POST, 1);
                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
                curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);                               
		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
                curl_setopt($ch, CURLOPT_POSTFIELDS, $param);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,30); 
		curl_setopt($ch, CURLOPT_TIMEOUT, 60); 		
                $result = curl_exec ($ch);
		break;
	} //switch
        $err = curl_error($ch);
        if($err) return $err;
	curl_close($ch);
	return $result;	
}

	 function request($Url, $Params, $Method='post'){

		$Curl = curl_init();

		if ('get' == $Method){
			curl_setopt($Curl, CURLOPT_URL, "$Url?$Params");
		}else{
			curl_setopt($Curl, CURLOPT_URL, $Url);
			curl_setopt($Curl, CURLOPT_POST, 1);
			curl_setopt($Curl, CURLOPT_POSTFIELDS, $Params);
		}

		curl_setopt($Curl, CURLOPT_HEADER, false);
		curl_setopt($Curl, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($Curl, CURLOPT_CONNECTTIMEOUT, 3);

		$Res = curl_exec($Curl);
		$Err = curl_error($Curl);
	  
		if (false === $Res || !empty($Err)){
			$Errno = curl_errno($Curl);
			$Info = curl_getinfo($Curl);
			curl_close($Curl);

			return array(
	        	'result' => false,
	        	'errno' => $Errno,
                        'msg' => $Err,
	        	'info' => $Info,
			);
		}
		curl_close($Curl);
		return array(
                    'result' => true,
                    'msg' => $Res,
		);
		 
	}
        